/**
 * @date 5:55:51 PM
 * SchoolController.java
 * Administrator
 * TODO
 */
package com.qs.education.controllers;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.api.ResponseListBean;
import com.qs.education.bean.beans.EducationSchoolBean;
import com.qs.education.bean.beans.EducationSchoolResponse;
import com.qs.education.bean.entity.EducationSchool;
import com.qs.education.bean.enums.ResponseStatus;
import com.qs.education.bean.utils.JsonUtil;
import com.qs.education.service.ISchoolAPIService;
/**
 * @class SchoolController	
 * @author Warren
 * @description
 * @date Nov 7, 2018 
 */
@RestController
public class SchoolController {
	
	@Autowired
	private ISchoolAPIService schoolAPIService;
	private final Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * @author Warren
	 * @return Map<String,Object>
	 * @description 获得所有学校
	 * @date Nov 8, 2018
	 */
	@RequestMapping("/school/getListAPI")
	public ResponseListBean<EducationSchoolBean> getList(HttpServletRequest request) {
		log.info("api");
		ResponseListBean<EducationSchoolBean> responselistBean = schoolAPIService.getList();
		return responselistBean;
	}
	
	/**
	 * @author Warren
	 * @param educationSchool
	 * @return Map<String,Object>
	 * @description 根据省市区选择所有学校
	 * @date Nov 8, 2018
	 */
	@RequestMapping("/school/getListByProvinceAndCityAndAreaAPI")
	public ResponseListBean<EducationSchoolBean> getListByProvinceAndCityAndArea(EducationSchool educationSchool) {
		log.info("api");
		ResponseListBean<EducationSchoolBean> responselistBean = schoolAPIService.getListByProvinceAndCityAndArea(educationSchool);
		return responselistBean;
	}
	
	/**
	 * @author Warren
	 * @param id 学生id
	 * @param schoolId 学校id
	 * @return Map<String,Object>
	 * @description
	 * @date Nov 8, 2018
	 */
	@RequestMapping("/school/selectSchool")
	public ResponseBean select(Long id,Long schoolId) {
		log.info("api");
		ResponseBean responseBean = schoolAPIService.selectSchool(id,schoolId);
		return responseBean;
	}
	
	/**
	 * @Description 添加学校
	 * @author Jason
	 * @date Nov 13, 2018
	 * @param request
	 * @param educationStudent
	 * @return
	 */
	@RequestMapping("/school/addSchoolAPI")
	public EducationSchoolResponse addSchool(HttpServletRequest request, String educationSchool) {
		
		log.info("api School 端 Controller  addSchool");
		EducationSchoolResponse response = new EducationSchoolResponse();
		response.setToken(response.getToken(request));
		EducationSchool school = (EducationSchool)JsonUtil.jsonToBean(educationSchool, EducationSchool.class);
		Boolean result = schoolAPIService.addSchool(school);
		if (result) {
			response.setStatus(ResponseStatus.SUCCESS.toString());
		}else {
			response.setStatus(ResponseStatus.FAILED.toString());
		}
		
		return response;
	}
	
	/**
	 * @Description 根据ID查询学校
	 * @author Jason
	 * @date Nov 14, 2018
	 * @param request
	 * @param studentId
	 * @return
	 */
	@RequestMapping("/school/findSchoolByIdAPI")
	public EducationSchoolResponse findSchoolById(HttpServletRequest request, Long schoolId) {
		
		log.info("api School 端 Controller  findSchoolById");
		EducationSchoolResponse response = new EducationSchoolResponse();
		response.setToken(response.getToken(request));
		response = schoolAPIService.findSchoolById(schoolId);
		response.setStatus(ResponseStatus.SUCCESS.toString());
		
		
		return response;
	}
	
	/**
	 * @Description 更新学校信息
	 * @author Jason
	 * @date Nov 14, 2018
	 * @param request
	 * @param studentId
	 * @return
	 */
	@RequestMapping("/school/updateSchoolAPI")
	public EducationSchoolResponse updateSchool(HttpServletRequest request, String educationSchool) {
		
		log.info("api School 端 Controller  updateSchool");
		EducationSchoolResponse response = new EducationSchoolResponse();
		EducationSchool school = (EducationSchool)JsonUtil.jsonToBean(educationSchool, EducationSchool.class);
		response.setToken(response.getToken(request));
		Boolean result = schoolAPIService.updateSchool(school);
		if (result) {
			response.setStatus(ResponseStatus.SUCCESS.toString());
		}else {
			response.setStatus(ResponseStatus.FAILED.toString());
		}
		
		return response;
	}
	
	/**
	 * @Description 删除学校信息
	 * @author Jason
	 * @date Nov 14, 2018
	 * @param request
	 * @param studentId
	 * @return
	 */
	@RequestMapping("/school/deleteSchoolAPI")
	public EducationSchoolResponse deleteSchoolAPI(HttpServletRequest request, Long schoolId) {
		
		log.info("api School 端 Controller  deleteSchool");
		EducationSchoolResponse response = new EducationSchoolResponse();
		response.setToken(response.getToken(request));
		Boolean result = schoolAPIService.deleteSchool(schoolId);
		if (result) {
			response.setStatus(ResponseStatus.SUCCESS.toString());
		}else {
			response.setStatus(ResponseStatus.FAILED.toString());
		}
		
		return response;
	}
}
